package com.example.mapp.buildSql;

import com.example.entity.authority.UserCheck;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by youkun on 2018/3/22.
 */
public class UserCheckMappSql {

    public String queryUserCheckList(UserCheck userCheck){

        String select = " id,user_name,role_Type_id,role_id,card_Type,party_Id," +
                "mobile,email,start_Time,success_Time,status,remarks,user_code ," +
                "card_Number,card_Type_Number,file_List,face_url,firstgt,phone";
        String table =" user_check ";
        String whereParam="";

        if(userCheck.getUserName()!=null && userCheck.getUserName().length()>0){
            userCheck.setUserName("%"+userCheck.getUserName()+"%");
            whereParam+=" and party_name like #{partyName}";
        }
        if(userCheck.getRoleId()!=null && userCheck.getRoleId().length()>0){
            whereParam+=" and role_id = #{roleId}";
        }
        if(userCheck.getRoleTypeId()!=null && userCheck.getRoleTypeId().length()>0){
            whereParam+=" and role_type_id = #{roleTypeId}";
        }
        if(userCheck.getStatus()!=null && userCheck.getStatus().length()>0){
            whereParam+=" and status = #{status}";
        }
        if(userCheck.getPartyId()!=null){
            whereParam+=" and party_id = #{partyId}";
        }
        String where = " 1=1 "+whereParam;
        String sql =  new SQL(){{
            SELECT(select);
            FROM(table);
            WHERE(where);
            ORDER_BY("id desc");
        }
        }.toString();

        return sql;
    }
}
